package com.free.lazy.common.utils;

import com.free.lazy.common.enums.ConstResponseEnum;
import lombok.Data;

@Data
public class ApiResult<T> {
    // 移除了原来的常量定义，现在使用 ConstResponseEnum 枚举

    private int code;
    private String message;
    private T data;
    
    public ApiResult() {
    }
    
    public ApiResult(ConstResponseEnum responseEnum) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public ApiResult(ConstResponseEnum responseEnum, String message) {
        this.code = responseEnum.getCode();
        this.message = message;
    }

    public ApiResult(ConstResponseEnum responseEnum, String message, T data) {
        this.code = responseEnum.getCode();
        this.message = message;
        this.data = data;
    }

    public ApiResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    // 为各种响应类型提供静态方法
    public static <T> ApiResult<T> success() {
        return new ApiResult<T>(ConstResponseEnum.SUCCESS);
    }

    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<T>(ConstResponseEnum.SUCCESS, "success", data);
    }

    public static <T> ApiResult<T> success(String message, T data) {
        return new ApiResult<T>(ConstResponseEnum.SUCCESS, message, data);
    }

    public static <T> ApiResult<T> fail() {
        return new ApiResult<T>(ConstResponseEnum.FAIL);
    }

    public static <T> ApiResult<T> fail(String message) {
        return new ApiResult<T>(ConstResponseEnum.FAIL, message);
    }

    public static <T> ApiResult<T> error() {
        return new ApiResult<T>(ConstResponseEnum.ERROR);
    }

    public static <T> ApiResult<T> error(String message) {
        return new ApiResult<T>(ConstResponseEnum.ERROR, message);
    }

    public static <T> ApiResult<T> notFound() {
        return new ApiResult<T>(ConstResponseEnum.NOT_FOUND);
    }

    public static <T> ApiResult<T> unauthorized() {
        return new ApiResult<T>(ConstResponseEnum.UNAUTHORIZED);
    }

    public static <T> ApiResult<T> forbidden() {
        return new ApiResult<T>(ConstResponseEnum.FORBIDDEN);
    }
}